package cn.ibizlab.odoo.core.odoo_calendar.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Icalendar_attendee;
import cn.ibizlab.odoo.core.odoo_calendar.domain.Calendar_attendee;
import cn.ibizlab.odoo.core.odoo_calendar.filter.Calendar_attendeeSearchContext;
import cn.ibizlab.odoo.core.odoo_calendar.service.ICalendar_attendeeService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[日历出席者信息] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Calendar_attendeeServiceImpl implements ICalendar_attendeeService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Icalendar_attendeeClientService calendar_attendeeClientService;

    @Override
    public void updateBatch(List<Calendar_attendee> calendar_attendees, int batchSize) {

        //calendar_attendeeClientService.updateBatch(calendar_attendees,batchSize) ;

    }

    @Override
    public void createBatch(List<Calendar_attendee> calendar_attendees, int batchSize) {

                        //calendar_attendeeClientService.createBatch(calendar_attendees,batchSize) ;

    }

    @Override
    public boolean update(Calendar_attendee calendar_attendee) {
        boolean bOk = false ;
        Icalendar_attendee clientModel = this.convert2Model(calendar_attendee,null);
        calendar_attendeeClientService.update(clientModel) ;
        this.convert2Domain(clientModel,calendar_attendee) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Icalendar_attendee clientModel = calendar_attendeeClientService.createModel();
        clientModel.setId(id);
        calendar_attendeeClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean create(Calendar_attendee calendar_attendee) {
        boolean bOk = false ;
        Icalendar_attendee clientModel = this.convert2Model(calendar_attendee,null);
        calendar_attendeeClientService.create(clientModel) ;
        this.convert2Domain(clientModel,calendar_attendee);
        bOk = true ;

        return bOk ;
    }

    @Override
    public Calendar_attendee get(Integer id) {
        Icalendar_attendee clientModel = calendar_attendeeClientService.createModel();
        clientModel.setId(id);
        calendar_attendeeClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Calendar_attendee get(Calendar_attendee calendar_attendee) {
        Calendar_attendee retcalendar_attendee = this.get(calendar_attendee.getId()) ;
    	BeanCopier copier=BeanCopier.create(retcalendar_attendee.getClass(), calendar_attendee.getClass(), false);
        copier.copy(retcalendar_attendee, calendar_attendee, null);
        return calendar_attendee ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //calendar_attendeeClientService.removeBatch(calendar_attendees) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Calendar_attendee> searchDefault(Calendar_attendeeSearchContext context) {
        List<Calendar_attendee> list = new ArrayList<Calendar_attendee>();
        Page<cn.ibizlab.odoo.core.client.model.Icalendar_attendee> clientModelList = calendar_attendeeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Icalendar_attendee clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Calendar_attendee>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据活动查询
     */
    @Override
    public Page<Calendar_attendee> selectByOdoo_event(Integer id){
        Calendar_attendeeSearchContext context = new Calendar_attendeeSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Calendar_attendee> list = new ArrayList<Calendar_attendee>();
        Page<cn.ibizlab.odoo.core.client.model.Icalendar_attendee> clientModelList = calendar_attendeeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Icalendar_attendee clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Calendar_attendee>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据联系人查询
     */
    @Override
    public Page<Calendar_attendee> selectByOdoo_partner(Integer id){
        Calendar_attendeeSearchContext context = new Calendar_attendeeSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Calendar_attendee> list = new ArrayList<Calendar_attendee>();
        Page<cn.ibizlab.odoo.core.client.model.Icalendar_attendee> clientModelList = calendar_attendeeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Icalendar_attendee clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Calendar_attendee>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Calendar_attendee> selectByOdoo_create(Integer id){
        Calendar_attendeeSearchContext context = new Calendar_attendeeSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Calendar_attendee> list = new ArrayList<Calendar_attendee>();
        Page<cn.ibizlab.odoo.core.client.model.Icalendar_attendee> clientModelList = calendar_attendeeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Icalendar_attendee clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Calendar_attendee>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Calendar_attendee> selectByOdoo_write(Integer id){
        Calendar_attendeeSearchContext context = new Calendar_attendeeSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Calendar_attendee> list = new ArrayList<Calendar_attendee>();
        Page<cn.ibizlab.odoo.core.client.model.Icalendar_attendee> clientModelList = calendar_attendeeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Icalendar_attendee clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Calendar_attendee>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Icalendar_attendee convert2Model(Calendar_attendee domain , Icalendar_attendee model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = calendar_attendeeClientService.createModel() ;
        }

         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getAccess_tokenDirtyFlag())
            model.setAccess_token(domain.getAccess_token());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getStateDirtyFlag())
            model.setState(domain.getState());
         if(domain.getCommon_nameDirtyFlag())
            model.setCommon_name(domain.getCommon_name());
         if(domain.getAvailabilityDirtyFlag())
            model.setAvailability(domain.getAvailability());
         if(domain.getEmailDirtyFlag())
            model.setEmail(domain.getEmail());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getPartner_id_textDirtyFlag())
            model.setPartner_id_text(domain.getPartner_id_text());
         if(domain.getEvent_id_textDirtyFlag())
            model.setEvent_id_text(domain.getEvent_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getEvent_idDirtyFlag())
            model.setEvent_id(domain.getEvent_id());
         if(domain.getPartner_idDirtyFlag())
            model.setPartner_id(domain.getPartner_id());
        return model ;
    }

    public Calendar_attendee convert2Domain( Icalendar_attendee model ,Calendar_attendee domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Calendar_attendee();
        }

        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getAccess_tokenDirtyFlag())
            domain.setAccess_token(model.getAccess_token());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getStateDirtyFlag())
            domain.setState(model.getState());
        if(model.getCommon_nameDirtyFlag())
            domain.setCommon_name(model.getCommon_name());
        if(model.getAvailabilityDirtyFlag())
            domain.setAvailability(model.getAvailability());
        if(model.getEmailDirtyFlag())
            domain.setEmail(model.getEmail());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getPartner_id_textDirtyFlag())
            domain.setPartner_id_text(model.getPartner_id_text());
        if(model.getEvent_id_textDirtyFlag())
            domain.setEvent_id_text(model.getEvent_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getEvent_idDirtyFlag())
            domain.setEvent_id(model.getEvent_id());
        if(model.getPartner_idDirtyFlag())
            domain.setPartner_id(model.getPartner_id());
        return domain ;
    }


}
